/**
 * Copyright(c) 2014 Xunton Solutions
 *
 * History:
 *   15-12-12 下午3:03 Created by dwzhang
 */
package com.jade.bss.ec.ware;

import java.io.Serializable;
import java.util.*;
import javax.persistence.*;

/**
 * 商品实体类，包括基本信息及其属性。
 *
 * @author <a href="mailto:dwzhang@xunton.com">dwzhang</a> 
 * @version 1.0 15-12-12 下午3:03
 */
@Entity
@Table (name = "BSS_EC_WARE")
public class Ware
        implements Serializable
{
    public static final int STATUS_NEW = 0;
    public static final int STATUS_ON_SALE = 1;
    public static final int STATUS_OFF_SALE = 2;
    //商品编号
    @Id
    @GeneratedValue (generator = "BSS_SEQ_EC_WARE")
    @SequenceGenerator (name = "BSS_SEQ_EC_WARE", sequenceName = "BSS_SEQ_EC_WARE")
    private long id;
    //商品所有者类型
    @Column (name = "owner_type", length = 32, nullable = false, updatable = false)
    private String ownerType;
    //商品所有者
    @Column (name = "owner_id", length = 64, nullable = false, updatable = false)
    private String ownerId;
    //商品名称
    @Column (name = "name", length = 128, nullable = false)
    private String name;
    //商品所属分类
    @Column (name = "cid", nullable = false)
    private long cid;
    //商品所属品牌
    @Column (name = "brand_id", nullable = false)
    private long brandId;
    //商品状态 - 0 - 未上架  1 - 上架  2 - 下架
    private int status = STATUS_NEW;
    //商品简介
    @Column (name = "remark", length = 512)
    private String remark;
    //详细信息
    @Lob
    private String details;
    //货号
    @Column (name = "cargo_number", length = 64)
    private String cargoNumber;
    //生产厂家
    @Column (name = "manufacturer", length = 64)
    private String manufacturer;
    //重量,单位为千克
    @Column (name = "weight")
    private double weight;
    //长度,单位为厘米
    @Column (name = "length")
    private float length;
    //宽度,单位为厘米
    @Column (name = "width")
    private float width;
    //高度,单位为厘米
    @Column (name = "height")
    private float height;
    //价格,单位为元
    @Column (name = "price")
    private double price;
    //市场价格,单位为元
    @Column (name = "market_price")
    private double marketPrice;
    //成本价格,单位为元
    @Column (name = "cost_price")
    private double costPrice;
    //库存，单位为个
    @Column (name = "stock_num")
    private long stockNum;
    //上架时间
    @Column (name = "sale_date")
    private Date saleDate;
    //创建时间
    @Column (name = "creation_date", nullable = false, updatable = false)
    private Date creationDate;
    //更新时间
    @Column (name = "update_date")
    private Date updateDate;
    //商品属性值
    @ElementCollection (targetClass = String.class, fetch = FetchType.EAGER)
    @CollectionTable (name = "BSS_EC_WARE_ATTR_VALUE", joinColumns = @JoinColumn (name = "wid"))
    @MapKeyColumn (name = "aid")
    @Column (name = "avalue", length = 1024)
    Map<Long, String> attrs;

    @Transient
    //商品图片，在不使用sku的时候使用
    private List<WareImage> images;
    @Transient
    private List<WareSku> skus;

    public long getId()
    {
        return id;
    }

    public void setId(long id)
    {
        this.id = id;
    }

    public String getOwnerType()
    {
        return ownerType;
    }

    public void setOwnerType(String ownerType)
    {
        this.ownerType = ownerType;
    }

    public String getOwnerId()
    {
        return ownerId;
    }

    public void setOwnerId(String ownerId)
    {
        this.ownerId = ownerId;
    }

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public long getCid()
    {
        return cid;
    }

    public void setCid(long cid)
    {
        this.cid = cid;
    }

    public long getBrandId()
    {
        return brandId;
    }

    public void setBrandId(long brandId)
    {
        this.brandId = brandId;
    }

    public int getStatus()
    {
        return status;
    }

    public void setStatus(int status)
    {
        this.status = status;
    }

    public String getRemark()
    {
        return remark;
    }

    public void setRemark(String remark)
    {
        this.remark = remark;
    }

    public String getDetails()
    {
        return details;
    }

    public void setDetails(String details)
    {
        this.details = details;
    }

    public String getCargoNumber()
    {
        return cargoNumber;
    }

    public void setCargoNumber(String cargoNumber)
    {
        this.cargoNumber = cargoNumber;
    }

    public String getManufacturer()
    {
        return manufacturer;
    }

    public void setManufacturer(String manufacturer)
    {
        this.manufacturer = manufacturer;
    }

    public double getWeight()
    {
        return weight;
    }

    public void setWeight(double weight)
    {
        this.weight = weight;
    }

    public float getLength()
    {
        return length;
    }

    public void setLength(float length)
    {
        this.length = length;
    }

    public float getWidth()
    {
        return width;
    }

    public void setWidth(float width)
    {
        this.width = width;
    }

    public float getHeight()
    {
        return height;
    }

    public void setHeight(float height)
    {
        this.height = height;
    }

    public double getPrice()
    {
        return price;
    }

    public void setPrice(double price)
    {
        this.price = price;
    }

    public double getMarketPrice()
    {
        return marketPrice;
    }

    public void setMarketPrice(double marketPrice)
    {
        this.marketPrice = marketPrice;
    }

    public double getCostPrice()
    {
        return costPrice;
    }

    public void setCostPrice(double costPrice)
    {
        this.costPrice = costPrice;
    }

    public long getStockNum()
    {
        return stockNum;
    }

    public void setStockNum(long stockNum)
    {
        this.stockNum = stockNum;
    }

    public Date getCreationDate()
    {
        return creationDate;
    }

    public void setCreationDate(Date creationDate)
    {
        this.creationDate = creationDate;
    }

    public Date getSaleDate()
    {
        return saleDate;
    }

    public void setSaleDate(Date saleDate)
    {
        this.saleDate = saleDate;
    }

    public Date getUpdateDate()
    {
        return updateDate;
    }

    public void setUpdateDate(Date updateDate)
    {
        this.updateDate = updateDate;
    }

    public Map<Long, String> getAttrs()
    {
        return attrs;
    }

    public void setAttrs(Map<Long, String> attrs)
    {
        this.attrs = attrs;
    }

    public void setAttr(long aid, String avalue)
    {
        if (attrs == null) {
            attrs = new HashMap<Long, String>();
        }
        attrs.put(aid, avalue);
    }

    public String getAttr(long aid)
    {
        return null == attrs ? null : attrs.get(aid);
    }

    public List<WareImage> getImages()
    {
        return images;
    }

    public void setImages(List<WareImage> images)
    {
        this.images = images;
    }

    public void addImage(WareImage image)
    {
        if (images == null) {
            images = new ArrayList<WareImage>();
        }
        images.add(image);

    }

    public List<WareSku> getSkus()
    {
        return skus;
    }

    public void setSkus(List<WareSku> skus)
    {
        this.skus = skus;
    }

    public void addSku(WareSku sku)
    {
        if (skus == null) {
            skus = new ArrayList<WareSku>();
        }
        skus.add(sku);
    }
}
